export function debounce(fn, delay = 800, immediate = false) {
    let timer = null;
    return function (...args) {
        if (timer) clearTimeout(timer);

        // 立即执行第一次
        if (immediate && !timer) {
            fn.apply(this, args);
        }

        timer = setTimeout(() => {
            if (!immediate) {
                fn.apply(this, args);
            }
            timer = null;
        }, delay);
    };
}